package com.qckj.amz.controller;

import com.qckj.amz.domain.ConfigMarketplace;
import com.qckj.amz.service.IConfigMarketplaceService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 站点维护Controller
 *
 * @author luchuan
 * @since 1.0 2021-11-08
 */
@RestController
@RequestMapping("/amz/marketplace")
public class ConfigMarketplaceController extends BaseController {
    @Autowired
    private IConfigMarketplaceService configMarketplaceService;

    /**
     * 查询站点维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigMarketplace configMarketplace) {
        Page<ConfigMarketplace> page = configMarketplaceService.findConfigMarketplacePage(configMarketplace);
        return getDataTable(page);
    }

    /**
     * 导出站点维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:export')")
    @Log(title = "站点维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigMarketplace configMarketplace) {
        List<ConfigMarketplace> list = configMarketplaceService.findConfigMarketplaceList(configMarketplace);
        ExcelUtil<ConfigMarketplace> util = new ExcelUtil<>(ConfigMarketplace.class);
        return util.exportExcel(list, "marketplace");
    }

    /**
     * 获取站点维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configMarketplaceService.findById(id));
    }

    /**
     * 新增站点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:add')")
    @Log(title = "站点维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigMarketplace configMarketplace) {
        configMarketplaceService.save(configMarketplace);
        return AjaxResult.success();
    }

    /**
     * 修改站点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:edit')")
    @Log(title = "站点维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigMarketplace configMarketplace) {
        configMarketplaceService.save(configMarketplace);
        return AjaxResult.success();
    }

    /**
     * 删除站点维护
     */
    @PreAuthorize("@ss.hasPermi('amz:marketplace:remove')")
    @Log(title = "站点维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configMarketplaceService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 同步汇率
     */
    @RequestMapping(value = "syncCurrencyRate")
    public AjaxResult syncCurrencyRate() {
        AjaxResult res = configMarketplaceService.syncCurrencyRate();
        return res;
    }


}
